package ch.subgate.pongwars;

import android.graphics.Canvas;

public abstract class Player extends GameObject {

    /** Saves the position from the preceding gameloop iteration */
    public float mLastX;

    /** Determines the size of the players paddle */
    public float mSize;

    /** Stores the current match points */
	public int mPoints;

    /** The speed of the current movement */
    public float mSpeed;

    /** Player A occupies the upper half of the screen */
    public boolean mIsPlayerRed;

    public Player(boolean isPlayerRed, float size) {
        super();
        mSize = size;
        mIsPlayerRed = isPlayerRed;
        mY = mIsPlayerRed ? Constants.PLAYER_RED_YPOS : Constants.PLAYER_BLUE_YPOS;
        // reset points from current match
        mPoints = 0;
        // place the player in the middle of the battlefield
        mX = Constants.DIC_BATTLEFIELD_WIDTH / 2.0f;
        // reset the players speed
        mSpeed = 0.0f;
    } // Constructor

    @Override
    public void draw(Canvas canvas, GameContext gameContext) {
        mR.set(
                gameContext.battlefieldLeft + ((mX - mSize) * gameContext.unitWidth),
                gameContext.battlefieldTop + ((mY - 0.5f) * gameContext.unitWidth),
                gameContext.battlefieldLeft + ((mX + mSize) * gameContext.unitWidth),
                gameContext.battlefieldTop + ((mY + 0.5f) * gameContext.unitWidth));

        if (mIsPlayerRed)
            mP.setColor(Constants.PLAYER_RED_PADDLE_COLOR);
        else
            mP.setColor(Constants.PLAYER_BLUE_PADDLE_COLOR);
        canvas.drawRect(mR, mP);
    } // draw

    public void reset() {
        // place the player in the middle of the battlefield
        mX = Constants.DIC_BATTLEFIELD_WIDTH / 2.0f;
    } // reset
	
} // Player
